package hutech.ksv.service;

import hutech.ksv.dao.AdminAccountDao;
import hutech.ksv.entity.QuanTriVienEntity;
import hutech.ksv.entity.TaiKhoanQTVEntity;
import hutech.ksv.entity.TaiKhoanSVEntity;
import hutech.ksv.entity.ThongTinTaiKhoanAdmin;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class AdminAccountService implements Serializable {
	
	@Autowired
	AdminAccountDao adminAccountDao;
	
	@Autowired
	EncryptMD5 encryptMD5;
	
	public ThongTinTaiKhoanAdmin checkLogin(String username, String password) {
		
		List<ThongTinTaiKhoanAdmin> listThongTinTaiKhoanAdmin = adminAccountDao.getThongTinTaiKhoanAdmin();
		
		password = encryptMD5.md5(password);
		
		for (ThongTinTaiKhoanAdmin thongTinTaiKhoanAdmin : listThongTinTaiKhoanAdmin) {
			if( thongTinTaiKhoanAdmin.getTenTKQTV().equals(username)
					&& thongTinTaiKhoanAdmin.getMatKauQTV().equals(password)) {				
				return thongTinTaiKhoanAdmin;
			}
		}
		
		return null;
	}
	
	public boolean isTaiKhoanAdminTonTai(String username) {
		ArrayList<String> danhSachTenTaiKhoanQTV = adminAccountDao.getTatCaTaiKhoanAdmin();
		
		for(int i = 0; i < danhSachTenTaiKhoanQTV.size(); i++) {
			if(username.equals(danhSachTenTaiKhoanQTV.get(i))) {
				return true;
			}
		}
		
		return false;
	}
	
	public int xoaQTVVuaNhap(int maQTV) {
		return adminAccountDao.xoaQuanTriVienVuaNhap(maQTV);
	}
	
	public int themQuanTriVien(QuanTriVienEntity quanTriVienEntity) {
		return adminAccountDao.themQuanTriVien(quanTriVienEntity);
	}
	
	public int themTaiKhoanQTV(TaiKhoanQTVEntity taiKhoanQTVEntity) {
		return adminAccountDao.themTaiKhoanQuanTriVien(taiKhoanQTVEntity);
	}

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

}
